import logging
import time

import pytest

from resource.pom.keyboard import Keyboard
from resource.pom.lock_screen import LockScreen
from resource.pom.settings import Settings
from utils.manager import Images


class Test:
    app = Settings
    keyboard = Keyboard
    lock_screen = LockScreen

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1.点击设置应用')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        logging.info('预期结果1.进入设置应用')
        device.assert_current_window(self.app.window_name)

        logging.info('步骤2.点击生物识别和密码')
        device.click(*self.app.biometrics_password_item)
        logging.info('预期结果2.进入生物识别和密码')
        device.refresh_layout()
        device.assert_text_exist('人脸识别')
        device.assert_text_exist('锁屏密码')

        logging.info('步骤3.点击人脸识别')
        device.click_element(device.get_element_by_text('人脸识别'))
        logging.info('预期结果3.进入临时认证界面(还未实现)')
        device.assert_current_window(self.app.faceauth_win)
        current_page = device.save_snapshot_to_local('face_page.jpeg')
        Images.crop_picture(current_page)
        similarity = Images.compare_image_similarity(current_page, self.app.face_auth_page)
        assert similarity > 0.8, '页面相似度和标准图差距过大'
